
package com.femass.converter;

import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.convert.Converter;
import javax.faces.convert.FacesConverter;
import com.femass.model.Tema;
import com.femass.repository.TemaRepository;
import com.femass.util.Repositorios;

@FacesConverter("temaConverter")
public class TemaConverter implements Converter {
    
    private Repositorios repositorios = new Repositorios();
    private TemaRepository temaRepo = this.repositorios.getTemas();
    
    @Override
    public Object getAsObject(FacesContext context, UIComponent component, String value) {
       
        if(!value.equals("")){
            return this.temaRepo.porCodigo(new Integer(value));
        }
        return null;
    }

    @Override
    public String getAsString(FacesContext context, UIComponent component, Object value) {
        if(value!=null){
            Integer codigo = ((Tema)value).getCod();
            return codigo==null ? "" : codigo.toString();
        }
        
        return null;
    }
        
    
}
